package practice;

import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;

/**
 * 身高相信的小朋友
 */
public class ChildrenOfSimilarHeight {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            String[] arr = sc.nextLine().split(" ");
            Integer selfHeight = Integer.parseInt(arr[0]);
            Arrays.stream(sc.nextLine().split(" "))
                    .map(Integer::parseInt).sorted((a, b) -> {
                        int sub1 = Math.abs(a - selfHeight);
                        int sub2 = Math.abs(b - selfHeight);
                        // 身高差相同 值小的排前面
                        if (sub1 == sub2) {
                            return a - b;
                        }
                        // 身高差不同 身高低的排前面
                        return sub1-sub2;
                    }).collect(Collectors.toList())
                    .forEach(height -> System.out.print(height + " "));
        }
    }
}
